<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>队伍考核-关联单位</title>
    <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet"/>
    <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet"/>

    <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
    <script src="${ctxStatic}/layui/layui.all.js" type="text/javascript"></script>

</head>
<body>
<form class="layui-form" id="formedit" name="formedit" action="create_kpiscore" method="post"
      target="d41d8cd98f00b204e9800998ecf8427e">
    <iframe name="d41d8cd98f00b204e9800998ecf8427e" src="about:blank" style="display:none;"></iframe>
    <div class="indexcontent">


        <div class="selftable" id="selftable">
            <table cellspacing="0" cellpadding="0" border="0" class="layui-table" style="margin:0;">
                <thead>

                <tr>
                    <th style="width: 150px">被评单位</th>
                    <c:forEach var="itemth" items="${titleh}" varStatus="idxStatus">
                        <th style="width: 60px">${itemth.uassingredients }<br>(${itemth.score}分)</th>
                    </c:forEach>
                    <th>总计</th>
                </tr>

                </thead>
                <tbody>
                <c:forEach var="item" items="${databody}" varStatus="idxStatus">
                    <tr>
                        <td>${item['orgname']}</td>
                        <c:forEach var="itembody" items="${titleh}" varStatus="idxStatus">
                            <td>
                                <input type="text"
                                       name="score_${item['orgid']}_${itembody.assindexid}"  
                                       maxNum="${itembody.score}"
                                       style="width: 60px;"
                                       lay-verify="required|number" autocomplete="off" class="layui-input"
                                       value="${item[itembody.assindexidcolum]}">
                            </td>
                        </c:forEach>
                        <td>${item['sumscore']}</td>
                    </tr>
                </c:forEach>

                </tbody>
            </table>
        </div>
    </div>
    <div class="layui-form" style="margin:0 auto;margin-top: 10px;width:90%;color:#ffffff">
        <table style="width:100%">
            <tr>
                <td style="text-align: center" colspan="2">
                    <button class="button" id="btnsave">保存打分</button>
                    <input class="button" value="关闭" class="button"
                           type="button" onclick="top.CloseOpenWindow()"/>
                </td>
                <td>
                    <input type="hidden" value="${templateid}" name="templateid">
                </td>
            </tr>
        </table>
    </div>
</form>

<script>
    var hs = new HashTable();
    var errNum = 0;
    $(function () {
        var form;
        var button;
        layui.use(['layer', 'form', 'button'], function () {
            form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
            button = layui.button;
            button.render();
            form.render();
        });
    })

    function CloseDialog(result, msg) {

        if (result > 0) {
            top.mylayui.msg('操作成功', {icon: 1});
        } else {
            top.mylayui.msg('操作失败', {icon: 0});
        }
        var index = parent.layer.getFrameIndex(window.name);

        parent.layer.close(index);
        return;
        // window.parent.test('2222222');
        top.frames["iframe"].vBTemplate.test(result);
    }

    function changedKpi(obj) {
        var element = $(obj);
        var maxNum = element.attr('maxNum');
        var value = element.val();

        if (parseFloat(value) > parseFloat(maxNum)) {
            layer.msg('分数不能超过' + maxNum, {icon: 0});
            if (!hs.containKey(element[0].name)) {
                hs.add(element[0].name, "");
            }
            // element.val('')
        } else {

            if (hs.containKey(element[0].name)) {
                hs.remove(element[0].name)
            }
        }


          if(hs.getSize()>0){

              $('#btnsave').attr('disabled',"true");//添加disabled属性
          }else{
              $('#btnsave').removeAttr("disabled"); //移除disabled属性
          }
    }


    // 创建构造函数HashTable
    function HashTable() {
        // 初始化哈希表的记录条数size
        var size = 0;

        // 创建对象用于接受键值对
        var res = {};

        // 添加关键字，无返回值
        this.add = function (key, value) {

            //判断哈希表中是否存在key，若不存在，则size加1，且赋值
            if (!this.containKey(key)) {
                size++;
            }

            // 如果之前不存在，赋值； 如果之前存在，覆盖。
            res[key] = value;
        };

        // 删除关键字, 如果哈希表中包含key，并且delete返回true则删除，并使得size减1
        this.remove = function (key) {
            if (this.containKey(key) && (delete res[key])) {
                size--;
            }
        };

        // 哈希表中是否包含key，返回一个布尔值
        this.containKey = function (key) {
            return (key in res);
        };

        // 哈希表中是否包含value，返回一个布尔值
        this.containValue = function (value) {

            // 遍历对象中的属性值，判断是否和给定value相等
            for (var prop in res) {
                if (res[prop] === value) {
                    return true;
                }
            }
            return false;
        };

        // 根据键获取value,如果不存在就返回null
        this.getValue = function (key) {
            return this.containKey(key) ? res[key] : null;
        };

        // 获取哈希表中的所有value, 返回一个数组
        this.getAllValues = function () {
            var values = [];
            for (var prop in res) {
                values.push(res[prop]);
            }
            return values;
        };

        // 根据值获取哈希表中的key，如果不存在就返回null
        this.getKey = function (value) {
            for (var prop in res) {
                if (res[prop] === value) {
                    return prop;
                }
            }

            // 遍历结束没有return，就返回null
            return null;
        };

        // 获取哈希表中所有的key,返回一个数组
        this.getAllKeys = function () {
            var keys = [];
            for (var prop in res) {
                keys.push(prop);
            }
            return keys;
        };

        // 获取哈希表中记录的条数，返回一个数值
        this.getSize = function () {
            return size;
        };

        // 清空哈希表，无返回值
        this.clear = function () {
            size = 0;
            res = {};
        };
    }
</script>

</body>
</html>